package org.springframework.test.common;

import org.springframework.beans.BeansException;
import org.springframework.beans.PropertyValue;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;

/**
 * @author derekyi
 * @date 2020/11/28
 */
public class CustomBeanFactoryPostProcessor implements BeanFactoryPostProcessor {

	@Override							//这里他会给你ioc容器，
	public void postProcessBeanFactory(ConfigurableListableBeanFactory beanFactory) throws BeansException {

		System.out.println("CustomBeanFactoryPostProcessor#postProcessBeanFactory");
		//可以得到你要的BeanDefiniton
		BeanDefinition personBeanDefiniton = beanFactory.getBeanDefinition("person");
		//在这个方法里你可以拿到读取进来的BeanDefinition(通过名称)
		PropertyValues propertyValues = personBeanDefiniton.getPropertyValues();
		//将person的name属性改为ivy,很简单
		propertyValues.addPropertyValue(new PropertyValue("name", "ivy"));
		//这个方法就是修改BeanDefinition的


	}
}
